package com.dgut.lotterySystem.dao.mapper;

import com.dgut.lotterySystem.dao.dataObject.PrizeDO;
import com.dgut.lotterySystem.dao.dataObject.PrizeInfoDO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;

import java.util.List;

@Mapper
public interface PrizeMapper {
    @Insert("insert into prize (name,description,price,image_url) values (#{name},#{description},#{price},#{imageUrl})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")//可以将库的id，映射到对象中的id；
    int insert(PrizeDO prizeDO);

    @Select("select count(*) from prize")
    Integer count();

    @Select("select id,name,description,price,image_url from prize order by id desc limit #{offset},#{pageSize}")
    List<PrizeInfoDO> selectPrizeInfoList(Integer offset,Integer pageSize);

    @Select("<script> " +
            "select id from prize " +
            "where id in " +
            "<foreach item='item' collection='prizeIds' open='(' separator=',' close=')'> " +
            "#{item} " +
            "</foreach> " +
            "</script>")
    List<Long> selectIdsByIds(List<Long> prizeIds);
    @Select("<script> " +
            "select * from prize " +
            "where id in " +
            "<foreach item='item' collection='prizeBaseIds' open='(' separator=',' close=')'> " +
            "#{item} " +
            "</foreach> " +
            "</script>")
    List<PrizeDO> batchSelectByIds(List<Long> prizeBaseIds);
    @Select("select * from prize where id=#{prizeId}")
    PrizeDO selectById(@Param("prizeId") Long prizeId);
}
